//
//  XLUserAccount.swift
//  SinaWeibo
//
//  Created by 李凯 on 16/9/4.
//  Copyright © 2016年 kevin. All rights reserved.
//

import UIKit

class XLUserAccount: NSObject, NSCoding {
    
    var access_token: String?
    var expires_in: Int = 0 {
        //外界设置过期时间时, 就计算出过期日期
        didSet{
            expireDate = Date(timeIntervalSinceNow: TimeInterval(expires_in))
        }
    }
    
    var uid: String?
    //定义过期日期
    var expireDate: Date?
    //获取用户数据
    //昵称
    var name: String?
    //头像
    var profileImgURL: String?
    
   
    
    init(dict: [String: Any]) {
        super.init()
        setValuesForKeys(dict)
    }
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        //空实现
    }
    
    //解档
    required init?(coder decoder: NSCoder) {
        access_token = decoder.decodeObject(forKey: "access_token") as? String
        expireDate = decoder.decodeObject(forKey: "expireDate") as? Date
        uid = decoder.decodeObject(forKey: "uid") as? String
        name = decoder.decodeObject(forKey: "name") as? String
        profileImgURL = decoder.decodeObject(forKey: "profileImgURL") as? String
    }
    
    //归档
    func encode(with encoder: NSCoder) {
        encoder.encode(access_token, forKey: "access_token")
        encoder.encode(expireDate, forKey: "expireDate")
        encoder.encode(uid, forKey: "uid")
        encoder.encode(name, forKey: "name")
        encoder.encode(profileImgURL, forKey: "profileImgURL")
    }

}
